package com.sttk.secreconeclick.bookkeep.utils;

import com.blankj.utilcode.util.GsonUtils;
import com.blankj.utilcode.util.SPUtils;
import com.google.gson.reflect.TypeToken;
import com.sttk.secreconeclick.bookkeep.bean.AccountBookBean;
import com.sttk.secreconeclick.bookkeep.bean.PlanBean;

import java.util.List;


public class AppSpUtils {
    private static final String SP_NAME = "appCollSp";
    private static final SPUtils sSpUtils = SPUtils.getInstance(SP_NAME);

    public static void saveAccountBookList(List<AccountBookBean> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_account_book_list, json);
    }

    public static List<AccountBookBean> getAccountBookList() {
        String json = sSpUtils.getString(Key.key_account_book_list);
        return GsonUtils.fromJson(json, new TypeToken<List<AccountBookBean>>() {
        }.getType());
    }

    public static void savePlanList(List<PlanBean> list) {
        String json = GsonUtils.toJson(list);
        sSpUtils.put(Key.key_plan_list, json);
    }

    public static List<PlanBean> getPlanList() {
        String json = sSpUtils.getString(Key.key_plan_list);
        return GsonUtils.fromJson(json, new TypeToken<List<PlanBean>>() {
        }.getType());
    }

    interface Key {
        String key_account_book_list = "key_account_book_list";
        String key_plan_list = "key_plan_list";
    }
}